package com.heima.admin.controller.v1;

import com.heima.admin.service.AdChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
@Api(value = "频道管理", tags = "频道管理", description = "频道管理API")
public class AdChannelController {

    @Autowired
    private AdChannelService adChannelService;

    /**
     * 根据频道名称分页查询频道列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("频道分页列表查询")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }

    /**
     * 新增频道
     * @param adChannel
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新增频道")
    public ResponseResult insert(@RequestBody AdChannel adChannel){
        return adChannelService.insert(adChannel);
    }

    /**
     * 更新频道
     * @param adChannel
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("更新频道")
    public ResponseResult update(@RequestBody AdChannel adChannel){
        return adChannelService.update(adChannel);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/del/{id}")
    @ApiOperation("删除频道")
    public ResponseResult deleteById(@PathVariable("id") Integer id){
        return adChannelService.deleteById(id);
    }

    /**
     * (自媒体的)频道列表展示
     * @return
     */
    @GetMapping("/channels")
    public ResponseResult listAll(){
        return ResponseResult.okResult(adChannelService.list());
    }
}